package com.atguigu.dga.governance.controller;

import com.atguigu.dga.governance.service.GovernanceAssessDetailService;
import com.atguigu.dga.governance.service.GovernanceAssessGlobalService;
import com.atguigu.dga.governance.service.GovernanceAssessTecOwnerService;
import com.atguigu.dga.governance.service.MainAssessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 治理考评结果明细 前端控制器
 * </p>
 *
 * @author wuzhida
 * @since 2024-06-26
 */
@RestController
@RequestMapping("/governance")
public class GovernanceAssessDetailController {
    
    @Autowired
    private GovernanceAssessGlobalService governanceAssessGlobalService;
    @Autowired
    private GovernanceAssessDetailService governanceAssessDetailService;
    @Autowired
    private GovernanceAssessTecOwnerService governanceAssessTecOwnerService;
    @Autowired
    private MainAssessService mainAssessService;

    /**
     * 全局分数
     * 返回值{"assessDate":"2023-04-01" ,"sumScore":90, "scoreList":[20,40,34,55,66]}
     */
    @GetMapping("/globalScore")
    public String globalScore(){
        return governanceAssessGlobalService.globalScore();
    }

    /**
     * 问题列表
     * 返回值
     * [{"assessComment":"","assessDate":"2023-05-01","assessProblem":"缺少技术OWNER","assessScore":0.00,"commentLog":"",
     * "createTime":1682954933000,"governanceType":"SPEC","governanceUrl":"/table_meta/table_meta/detail?tableId=1803",
     * "id":21947,"isAssessException":"0","metricId":1,"metricName":"是否有技术Owner","schemaName":"gmall",
     * "tableName":"ads_page_path"}
     * ...
     * ]
     */
    @GetMapping("/problemList/{governType}/{pageNo}/{pageSize}")
    public String problemList(
            @PathVariable("governType") String governType,
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("pageSize") Integer pageSize){
        return governanceAssessDetailService.getProblemList(governType, pageNo, pageSize);
    }

    /**
     * 各个治理类型问题个数
     * 返回值 {"SPEC":1, "STORAGE":4,"CALC":12,"QUALITY":34,"SECURITY":12}
     */
    @GetMapping("/problemNum")
    public String problemNum(){
        return governanceAssessDetailService.getProblemNum();
    }

    /**
     * 分组人员排行榜
     * 返回值 
     * [{"tecOwner":"zhang3" ,"score":99},
     * {"tecOwner":"li4" ,"score":98},
     * {"tecOwner": "wang5","score":97}   ]
     */
    @GetMapping("/rankList")
    public String getRankList(){
        return governanceAssessTecOwnerService.getRankList();
    }

    /**
     * 手动触发评估
     */
    @PostMapping("/assess/{date}")
    public String assess(@PathVariable String date){
        mainAssessService.mainAssess(date);
        return "success";
    }
    
}
